﻿using System.IO;
using ProtoBuf;

namespace CenterServerDemo
{
    public class ProtobufSerializeProvider:ISerializeProvider 
    {
        public T Deserialize<T>(byte[] data) where T:class
        {
            try
            {

                using (var memory = new MemoryStream(data))
                {
                    return Serializer.Deserialize<T>(memory);
                }
            }
            catch
            {
                return default(T);
            }
          
        }

        public byte[] Serialize<T>(T t)
        {
            using (var memory = new MemoryStream())
            {
                Serializer.Serialize(memory, t);
                return memory.ToArray();
            }
        }
    }
}